//
//  UIScrollView+HYRefresh.m
//  HYRefresh
//
//  Created by HYMac on 16/3/4.
//  Copyright © 2016年 HYMac. All rights reserved.
//

#import "UIScrollView+HYRefresh.h"
#import "HYHeadRefreshView.h"
#import "HYFootRefreshView.h"
#import <objc/runtime.h>

@interface UIScrollView()
@property(nonatomic, weak)HYHeadRefreshView *headView;
@property(nonatomic, weak)HYFootRefreshView *footView;
@end

@implementation UIScrollView (HYRefresh)
static char HYRefreshHeaderViewKey;
static char HYRefreshFootViewKey;
-(void)setHeadView:(HYHeadRefreshView *)headView
{
    objc_setAssociatedObject(self, &HYRefreshHeaderViewKey, headView, OBJC_ASSOCIATION_ASSIGN);
}
-(HYHeadRefreshView *)headView
{
    return   objc_getAssociatedObject(self, &HYRefreshHeaderViewKey);
}
-(void)setFootView:(HYFootRefreshView *)footView
{
    objc_setAssociatedObject(self, &HYRefreshFootViewKey, footView, OBJC_ASSOCIATION_ASSIGN);
}
-(HYFootRefreshView *)footView
{
    return objc_getAssociatedObject(self, &HYRefreshFootViewKey);
}
-(void)addHeadRefreshWithTarget:(id)target action:(SEL)action
{
    HYHeadRefreshView *headView=[[HYHeadRefreshView alloc]init];
    self.headView=headView;
    headView.scrollView=self;
    headView.target=target;
    headView.action=action;
    [self addSubview:headView];
}
-(void)addFootRefreshWithTarget:(id)target action:(SEL)action
{
    HYFootRefreshView *footView=[[HYFootRefreshView alloc]init];
    self.footView=footView;
    footView.scrollView=self;
    footView.target=target;
    footView.action=action;
    [self addSubview:footView];

}
-(void)endHeadRefresh
{
    self.headView.state=refreshStateNoneNormal;
    self.contentInset=UIEdgeInsetsMake(0, 0, 0, 0);
}
-(void)endFootRefresh
{
   self.footView.state=refreshStateNoneNormal;
    self.contentInset=UIEdgeInsetsMake(0, 0, 0, 0);
}
@end